//
//  MemberCenterVC.m
//  hnGovernment
//
//  Created by 安仔 on 17/2/24.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "MemberCenterVC.h"
#import "MCHeaderView.h"
#import "HYImagePicker.h"

#import "LoginVC.h"
#import "PersonInformVC.h"
#import "IdentityVerificationVC.h"

#import "MemberCenterCell.h"
#import "SystemSettingVC.h"
#import "MyMessageTV.h"
#import "WorkingRecordController.h"
#import "PayRecordTV.h"
#import "ConsultRecordTV.h"
#import "ComplainRecordTV.h"
#import "SuggestVC.h"
#import "CollectRecordTV.h"
#import "DDcacheManager.h"
#import "XJNavigationController.h"
#import "ManagementAddressVC.h"
#import "DDNetworkSwitchHelper.h"

@interface MemberCenterVC ()

@end

@interface MemberCenterVC ()<UITableViewDelegate, UITableViewDataSource, MCHeaderViewDelegate>
@property (nonatomic, strong) UITableView *myTableView;
@property (nonatomic, strong) NSArray *myTVDataArr;
@property (nonatomic, strong) UIView *headerView;

@property (nonatomic, strong) MCHeaderView *mcHeaderView;


@end

@implementation MemberCenterVC

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = YES;
    [self.mcHeaderView updataUserStatus];
}

- (void)viewWillDisappear:(BOOL)animated {
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = RGB(237, 237, 237);
    
    [self setUpData];
    [self createUI];
    
}

//初始化数据
- (void)setUpData {
    NSDictionary *dic1 = @{@"image":@"menberCenter_working",
                           @"title":NSLocalString(@"我的办件")};
    NSDictionary *dic2 = @{@"image":@"menberCenter_pay",
                           @"title":NSLocalString(@"我的支付")};
    NSDictionary *dic3 = @{@"image":@"menberCenter_consult",
                           @"title":NSLocalString(@"我的咨询")};
    NSDictionary *dic4 = @{@"image":@"menberCenter_complain",
                           @"title":NSLocalString(@"我的投诉")};
    NSDictionary *dic5 = @{@"image":@"menberCenter_suggest",
                           @"title":NSLocalString(@"我的建议")};
    NSDictionary *dic6 = @{@"image":@"menberCenter_collect",
                           @"title":NSLocalString(@"我的收藏")};
    NSDictionary *dic7 = @{
                            @"image":@"",
                            @"title":NSLocalString(@"切换服务器")
                            };
    
    self.myTVDataArr = @[dic1, dic2, dic3, dic4, dic5, dic6, dic7];
//    self.myTVDataArr = @[dic1, dic2, dic3, dic4, dic5, dic6];
}


- (void)createUI {
    
    self.mcHeaderView = [[MCHeaderView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 410 * m6Scale)];
    self.mcHeaderView.delegate = self;
    [self.view addSubview:self.mcHeaderView];
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 430 * m6Scale, KScreenWidth, 720 * m6Scale) style:UITableViewStylePlain];
    self.myTableView.backgroundColor = RGB(237, 237, 237);
    self.myTableView.dataSource = self;
    self.myTableView.delegate = self;
    self.myTableView.scrollEnabled = NO;
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.myTableView];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.myTVDataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MemberCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellid"];
    if (!cell) {
        cell = [[MemberCenterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellid"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary *dict = self.myTVDataArr[indexPath.row];
    cell.titleLab.text = dict[@"title"];
    cell.signImg.image = [UIImage imageNamed:dict[@"image"]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 102 * m6Scale;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSLog(@"点击了第%ld行", (long)indexPath.row);

    if (indexPath.row == 0) {
        self.navigationController.navigationBar.hidden = NO;
        WorkingRecordController *vc = [[WorkingRecordController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row == 1) {
        self.navigationController.navigationBar.hidden = NO;
        PayRecordTV *vc = [[PayRecordTV alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row == 2) {
        self.navigationController.navigationBar.hidden = NO;
        ConsultRecordTV *vc = [[ConsultRecordTV alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if (indexPath.row == 3) {
        self.navigationController.navigationBar.hidden = NO;
        ComplainRecordTV *vc = [[ComplainRecordTV alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
        
    }
    else if (indexPath.row == 4) {
        self.navigationController.navigationBar.hidden = NO;
        SuggestVC *vc = [[SuggestVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
        
    }
    else if (indexPath.row == 5){
        self.navigationController.navigationBar.hidden = NO;
        CollectRecordTV *vc = [[CollectRecordTV alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }else {
        [[DDNetworkSwitchHelper shateInstance]showSwitchMenu];
    }
}

- (void)chooseHeadImg {
    
    if ([cacheManager getUserModel]) {
        PersonInformVC *infoVC = [[PersonInformVC alloc]init];
        [self.navigationController pushViewController:infoVC animated:YES];
    }else {
        LoginVC *loginVC = [[LoginVC alloc] init];
        [self.navigationController pushViewController:loginVC animated:YES];
    }
    
//    //头像
//    HYImagePicker *imgPicker = [[HYImagePicker alloc] init];
//    imgPicker.allowsEditing = YES;
//    imgPicker.isNeedScale = YES;
//    [imgPicker showWith:self];
//
}

#pragma mark - HYImagePicker 代理方法
- (void)imagePicker:(HYImagePicker *)imagePicker type:(MediaType)type and:(NSString *)path
{
  
}


- (void)checkSureIDBtn {
    
    self.navigationController.navigationBar.hidden = NO;
    IdentityVerificationVC *vc = [[IdentityVerificationVC alloc] init];
    [self.navigationController pushViewController:vc animated:YES];

}

- (void)checkMemberCenterMessage {
    
    self.navigationController.navigationBar.hidden = NO;
    MyMessageTV *systemSettingVC = [[MyMessageTV alloc] init];
    [self.navigationController pushViewController:systemSettingVC animated:YES];
}

- (void)checkMCSettingBtn {
    
    self.navigationController.navigationBar.hidden = NO;
    SystemSettingVC *systemSettingVC = [[SystemSettingVC alloc] init];
    [self.navigationController pushViewController:systemSettingVC animated:YES];
    
}

- (void)checkUnfinishedBtn {
    NSLog(@"代办理");
}

- (void)checkFinishedBtn {
    NSLog(@"已结办");
}

@end
